/*
 * APICloud JavaScript Library
 * Copyright (c) 2014 apicloud.com
 */
(function(window){
    var u = {};
    var isAndroid = (/android/gi).test(navigator.appVersion);
    var uzStorage = function(){
        var ls = window.localStorage;
        if(isAndroid){
           ls = os.localStorage();
        }
        return ls;
    };

		u.openFrame=function(obj, param,bgc,isValid){
			console.log(2);
			
			if(typeof obj == Object){
				api.openFrame({
			        name: obj.name,
			        url: obj.url,
		            pageParam:param,
			        bounces:obj.bounces?obj.bounces:false,
			        bgColor:bgc,
			        reload : obj.reload?obj.reload : false,
			        vScrollBarEnabled:false,
			        rect: {
				        x:0,
				        y:0,
				        w:'auto',
				        h:'auto',
				        marginTop:obj.marginTop+25,
				        marginBottom:obj.marginBottom
			        }
	      	 	});
     	}else{
     			window.location.href=app.link.apiUrl+'/'+url;
     			if(param){
     				app.store('url',''+param+'');
     			}
     		}
		}
		
		u.openWin=function(obj,param,bgc,isValid){
			if(isValid){
				var token = app.store('token');
				if (!token) {
					api.openWin({
			    		name:'member.login',
			    		url:'member.login.html'
			    	});
			    	return;
				}
			}
			api.openWin({
				name: obj.name,   
	        url: obj.url,
	        bounces:false,
	        pageParam:param,
	        bgColor:bgc,
	        reload : obj.reload?obj.reload : false,
	        rect: {
		        x:0,
		        y:0,
		        w:'auto',
		        h:'auto',
		        marginTop:obj.marginTop,
		        marginBottom:obj.marginBottom
	        }
			});
		}
		
		u.showProgress=function(msg){
			api.showProgress({
				title:msg
       		});
		}
		
		u.closeWin=function(){
			api.closeWin({
		      	name: api.winName
		    });
       };
       
		//左箭头返回
	var back=document.getElementsByClassName('icon-jiantouzuo')[0];
		if(back){
			back.onclick=function(){
				api.closeWin({
		      	name: api.winName
		    });
			}
		}
		
	u.alert=function(){
			api.alert({
				    title: '优购100',
				    msg: '您还没有登录哦~请先登录！'
			}, function(ret, err){
					$api.openWin({
							name:'member.login',
							url:'member.login.html'
						});
						return;
			});
	}
/*end*/
   
    window.$api = u;

})(window);
	
